#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "singleton.h"
#include "dptr.h"

#include <QCloseEvent>
#include <QMdiArea>
#include <QMdiSubWindow>
//#include <QMdiChild>
 class MdiChild;
//QT_BEGIN_NAMESPACE
//class QAction;
//class QMenu; //class QMdiArea;
//class QMdiSubWindow;
//QT_END_NAMESPACE

class MainWindowPrivate;
class MainWindow : public QMainWindow
{
    DPTR_DECLARE_PRIVATE(MainWindow)
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    virtual ~MainWindow() override;

    QMdiArea *getMdiArea();
    QMdiSubWindow *addSubWindow(QWidget *w);

    bool openFile(const QString &fileName);

    void enter(void);
    void leave(void);
signals:

private slots:
    void newFile();
    void open();
    void save();
    void saveAs();
    void updateRecentFileActions();
    void openRecentFile();

#ifndef QT_NO_CLIPBOARD
    void cut();
    void copy();
    void paste();
#endif
    void about();
    void updateMenus();
    void updateWindowMenu();
    MdiChild *createMdiChild();
    void switchLayoutDirection();

protected:
    void closeEvent(QCloseEvent *event) override;

    explicit MainWindow(MainWindowPrivate &d, QWidget *parent = nullptr);
    DPTR_DECLARE(MainWindow)
    SINGLETON_DECLARE(MainWindow)

private:
    void createActions();
    void createStatusBar();
    void readSettings();
    void writeSettings();
    bool loadFile(const QString &fileName);
    static bool hasRecentFiles();
    void prependToRecentFiles(const QString &fileName);
    void setRecentFilesVisible(bool visible);
    MdiChild *activeMdiChild() const;
    QMdiSubWindow *findMdiChild(const QString &fileName) const;

};

#define mainwindow MainWindow::getInstance()

#endif // MAINWINDOW_H
